<template>
    <div class="historylist">
       <wxc-minibar title="历史开奖">
            <!-- <image slot="left" src="http://zhongcai-test.oss-cn-beijing.aliyuncs.com/back_icon.png"  style="height:28px;width:16px;"></image>
            <text slot="middle" style="font-family: PingFangSC-Medium;font-size: 34px;color: #fff;">历史开奖</text> -->
       </wxc-minibar>
       <div>
         <scroller class="scroller" style="position:fixed;top:90px;bottom:0;left:0;right:0;background-color: #F5F5F5;padding-top:24px;">
            <div class="lottery_first" v-for="(item,index) in lotterylist" :key="index" @click="godetail(item)">
                <div class="lottery_first_box">
                    <div class="lottery_first_info">
                        <div class="lottery_first_info_fl">
                        <!-- <text class="bigtitle">{{item.title}}</text> -->
                        <text class="bigtitle" v-if="id==1">双色球</text>
                        <text class="bigtitle" v-if="id==2">超级大乐透</text>
                        <text class="bigtitle" v-if="id==3">福彩3D</text>
                        <text class="bigtitle" v-if="id==4">排列三</text>
                        <text class="bigtitle" v-if="id==5">排列五</text>
                        <text class="subtitle">第{{item.issue}}期</text>
                        </div>
                        <div class="lottery_first_info_fr">
                        <text class="desc">{{item.drawTime | filtertime}}</text>
                        </div>
                    </div>
                    <div class="lottery_first_ball">
                        <div :class="[item.lottery_id==1||item.lottery_id==2?'bGroup':'bGroup1']">
                            <text :class="[item.lottery_id==1||item.lottery_id==2?'forward':'forward1']" v-for="(item1,index) in item.forward" :key="index+1/4">{{item1}}</text>
                            <text class="backward" v-for="(item1,index) in item.backward" :key="index+1/5">{{item1}}</text>
                        </div>
                    </div>
                </div>
            </div>
            <!-- <loading class="loading" @loading="onloading" :display="loadinging ? 'show' : 'hide'">
              <loading-indicator class="indicator"></loading-indicator>
            </loading> -->
         </scroller>
       </div>
    </div>
</template>

<script>
const modal = weex.requireModule("modal");
let navigator = weex.requireModule('navigator')
import { GetResponsesToken } from '@/api'
import WxcMinibar from "@/components/modules/wxc-minibar/index.js"
import { serialize, getBaseUrl, jsonAnalysis }  from "@/utils/index.js"
import { lotteryTypes } from "@/js/global/index_data.js"

var sxglobalEvent = weex.requireModule("globalEvent");
export default {
	data() {
		return {
		id: '',
		loadinging: false,
		lotterylist: []
		};
	},
	filters: {
		filtertime(time) {
				let iarr = ['周日','周一','周二','周三','周四','周五','周六']
				let date = new Date(+time)
				
				let formatNum = (num) => { return num < 10 ? "0" + num : num.toString() }

				return `${ date.getFullYear() }-${formatNum(date.getMonth() + 1)}-${ formatNum(date.getDate())} ${iarr[date.getDay()]}`
			}
	},
	created() {
		// 获取路径
		this.baseURL = getBaseUrl(weex.config.bundleUrl, true)
		let personalDetails = jsonAnalysis(weex.config.bundleUrl.split('?')[1])
		this.id = personalDetails.id;

		let param = ['SSQ', 'DLT', 'FC3D', 'PL3', 'PL5']


		this.historyList(param[this.id-1])
	},

	components:{
		WxcMinibar
	},

	methods: {
		godetail(item) {
			var param = {
				id: this.id,
				issue: item.issue,
				drawtime: item.drawTime,
				forward: item.forward.join(','),
				backward: item.backward.join(',') || '',
				prize: item.prize
			}
    
			

			navigator.push({
				'url': this.baseURL + 'views/drawLottery/lotto-detail.js?'+ serialize(param),
				'animated': 'true'
			})

		},

		splitNum(num, state) {
			return !!state ? [num.split('+')[0].split(','), num.split('+')[1].split(',') ] : num.split(',')
		},

		onloading(event) {
			this.loadinging = true;
			setTimeout(() => {
				this.lotterylist = this.lotterylist.concat(this.lotterylist);
				this.loadinging = false;
			}, 2000);
		},

		async historyList(id) {
      let data = await GetResponsesToken(`lottery/history/oneDraws/${id}/1`)
      			// let data = await GetResponsesToken(`lottery/history/oneDraws/SSQ/1`);


			this.lotterylist = data.data.map((item)=>{
				let data = this.splitNum(item.drawNumber, item.drawNumber.indexOf('+') > -1 )
			
				if( item.drawNumber.indexOf('+') > -1 ) {
					item.forward = data[0]
					item.backward = data[1]
				} else {
					item.forward = data
					item.backward = []
				}

				return item
      })
      console.log(this.lotterylist);
		}
	}
};
</script>
<style scoped>
.header {
  width: 750px;
  height: 90px;
  background-color: #fff;
  box-shadow: 0 4px 15px 0 rgba(229, 229, 229, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}
.img_left{
  position: absolute;
  top: 0;
  display: flex;
  flex-direction: row;
  align-items: center;

  width: 100px;
  height: 90px;
  left:32px;
}
.header-title {
  font-size: 34px;
  color: #fff;
  font-family: PingFangSC-Medium;
}
.header-img-right {
  position: absolute;
  right: 32px;
  top: 34px;
  margin-left: 0;
}
.bigtitle {
  font-family: PingFangSC-Medium;
  font-size: 32px;
  color: #333333;
}
.subtitle {
  font-size: 28px;
  color: #666666;
  margin-left: 24px;
}
.desc {
  font-size: 24px;
  color: #a7a7a7;
}
.lottery_first {
  background-color: #ffffff;
}

.lottery_first_box {
  width: 750px;
  padding-top: 32px;
  padding-left: 32px;
  padding-right: 32px;
  box-sizing: border-box;
}
.lottery_first_info {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.lottery_first_info_fl {
  align-items: center;
  display: flex;
  flex-direction: row;
  flex: 400px;
}
.lottery_first_info_fr {
  align-items: center;
  display: flex;
  flex-direction: row;
  flex: 200px;
}
.bGroup {
  padding: 24px 16px 32px 16px;
  display: flex;
  justify-content: space-between;
  flex-direction: row;
  border-bottom-width: 1px;
  border-bottom-style: solid;
  border-bottom-color: rgba(0, 0, 0, 0.1);
}
.bGroup1{
  padding: 24px 16px 32px 16px;
  display: flex;
  flex-direction: row;
  border-bottom-width: 1px;
  border-bottom-style: solid;
  border-bottom-color: rgba(0, 0, 0, 0.1);
}
.forward1{
  background-color: #e70d0d;
  color: #fff;
  font-size: 32px;
  height: 64px;
  line-height: 64px;
  width: 64px;
  border-radius: 50%;
  display: flex;
  text-align: center;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  margin-right: 34px;
}
.forward {
  background-color: #e70d0d;
  color: #fff;
  font-size: 32px;
  height: 64px;
  line-height: 64px;
  width: 64px;
  border-radius: 50%;
  display: flex;
  text-align: center;
  align-items: center;
  flex-direction: column;
  justify-content: center;
}
.backward {
  font-size: 32px;
  height: 64px;
  line-height: 64px;
  width: 64px;
  border-radius: 50%;
  display: flex;
  text-align: center;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: #076bf2;
  color: #fff;
  margin-right: 34px;
}
.lottery_first_ball {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.loading {
  width: 750px;
  height: 100px;
  display: flex;
  background-color: #333;
  -ms-flex-align: center;
  -webkit-align-items: center;
  -webkit-box-align: center;
  align-items: center;
  background-color: #f5f5f5;
}
.indicator-text {
  color: #888888;
  font-size: 20px;
  text-align: center;
}
.indicator {
  margin-top: 16px;
  height: 40px;
  width: 40px;
  color: gray;
}

.border-bottom{
  border-bottom-color: #f1f1f1;
  border-bottom-width: 1px;
  border-bottom-style: solid;
}
</style>